/*
 * Copyright (C) 2011 mAPPn.Inc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.mol.market.common.util;

import com.mol.market.R;
import com.mol.market.Session;

/**
 * 主题管理器
 * 
 * @author rachel
 */
public class ThemeManager {

    /**
     * 浅色主题
     */
    public static final int THEME_TYPE_LIGHT = 1;

    /**
     * 深色主题
     */
    public static final int THEME_TYPE_DARK = 2;

    public static final int KEY_HOME_TAB_INDEX = 1;
    public static final int KEY_HOME_TAB_CATEGORY = 2;
    public static final int KEY_HOME_TAB_RECOMMEND = 3;
    public static final int KEY_HOME_TAB_RANK = 4;
    public static final int KEY_HOME_TAB_APP_MANAGER = 5;
    public static final int KEY_HOME_TAB_BREATH = 20;
    public static final int KEY_HOME_TAB_BACKGROUND = 31;
    public static final int KEY_HOME_TAB_INDICATOR = 43;

    public static final int KEY_TAB_M = 6;
    public static final int KEY_TAB_L = 7;
    public static final int KEY_TAB_R = 8;
    public static final int KEY_TAB_BG = 14;

    public static final int KEY_FEED_BACK_EDIT_TEXT = 9;
    public static final int KEY_FEED_BACK_BTN = 10;
    public static final int KEY_HOME_TAB_TEXT = 11;
    public static final int KEY_TAB_TEXT = 12;
    public static final int KEY_TOP_TITLE_TEXT = 13;
    
    public static final int KEY_ACTION_BAR_BG = 15;
    public static final int KEY_ACTION_BAR_OPERATION_BG = 16;
    public static final int KEY_ACTION_BAR_FONT = 17;
    public static final int KEY_ACTION_BAR_FONT_M = 18;
    public static final int KEY_ACTION_BAR_FONT_S = 36;
    public static final int KEY_ACTION_BAR_SPLITTER = 19;
    public static final int KEY_ACTION_BAR_BTN_BG = 37;
    
    public static final int KEY_ACTION_BAR_DOWNLOAD = 21;
    public static final int KEY_ACTION_BAR_PENDING = 22;
    public static final int KEY_ACTION_BAR_INSTALL = 23;
    public static final int KEY_ACTION_BAR_OPEN = 24;
    public static final int KEY_ACTION_BAR_UNINSTALL = 25;
    public static final int KEY_ACTION_BAR_UP = 26;
    public static final int KEY_ACTION_BAR_UP_CHECKED = 27;
    public static final int KEY_ACTION_BAR_DOWN = 28;
    public static final int KEY_ACTION_BAR_DOWN_CHECKED = 29;
    public static final int KEY_ACTION_BAR_CANCEL = 41;
    public static final int KEY_ACTION_BAR_START = 44;
    
    public static final int KEY_TOP_BAR_BG = 30;
    public static final int KEY_TOP_BAR_SEARCH = 32;
    public static final int KEY_TOP_BAR_LOGO = 33;
    public static final int KEY_TOP_BAR_SPLITTER = 34;
    public static final int KEY_TOP_BAR_SHARE = 35;
    public static final int KEY_TOP_BAR_FOLLOW = 38;
    public static final int KEY_TOP_BAR_BTN_BG = 42;
    
    public static final int KEY_PROGRESSBAR = 40;
    
    public static final int KEY_TOP_BAR_EXCHANGE = 45;

    /**
     * 获取当前主题下对应的资源ID
     */
    public static int getResource(Session session, int resId) {

        int theme = session.getTheme();
        switch (theme) {
        case ThemeManager.THEME_TYPE_LIGHT:
            return getLightResourceId(resId);
        case ThemeManager.THEME_TYPE_DARK:
            return getDarkResourceId(resId);
        default:
            return getDarkResourceId(resId);
        }
    }

    /*
     * 返回浅色主题资源
     */
    private static int getLightResourceId(int resId) {

        switch (resId) {
        case KEY_HOME_TAB_INDEX:
            return R.drawable.main_tab_index_selector_light;
        case KEY_HOME_TAB_CATEGORY:
            return R.drawable.main_tab_category_selector_light;
        case KEY_HOME_TAB_RECOMMEND:
            return R.drawable.main_tab_recommend_selector_light;
        case KEY_HOME_TAB_RANK:
            return R.drawable.main_tab_rank_selector_light;
        case KEY_HOME_TAB_APP_MANAGER:
            return R.drawable.main_tab_app_manager_selector_light;
        case KEY_TAB_M:
            return R.drawable.tab_selector_light;
        case KEY_TAB_L:
            return R.drawable.tab_l_bg_selector_light;
        case KEY_TAB_R:
            return R.drawable.tab_r_bg_selector_light;
        case KEY_HOME_TAB_TEXT:
            return R.style.home_tab_text_style_light;
        case KEY_TAB_TEXT:
            return R.style.tab_text_style_light;
        case KEY_TOP_TITLE_TEXT:
            return R.style.app_text_style1;
        case KEY_TAB_BG:
            return R.drawable.tab_bg_light;
        case KEY_ACTION_BAR_BG:
            return R.drawable.action_bar_operation_bg_light;
        case KEY_ACTION_BAR_OPERATION_BG:
            return R.drawable.action_bar_operation_bg_light;
        case KEY_ACTION_BAR_FONT:
            return R.style.text_style_3b;
        case KEY_ACTION_BAR_FONT_M:
            return R.style.text_style_2b;
        case KEY_ACTION_BAR_SPLITTER:
            return R.drawable.action_bar_splitter_light;
        case KEY_HOME_TAB_BREATH:
            return R.drawable.master_breath_drawable_light;
        case KEY_ACTION_BAR_DOWNLOAD:
            return R.drawable.action_bar_download_light;
        case KEY_ACTION_BAR_PENDING:
            return R.drawable.action_bar_pending_light;
        case KEY_ACTION_BAR_INSTALL:
            return R.drawable.action_bar_install_light;
        case KEY_ACTION_BAR_UNINSTALL:
            return R.drawable.action_bar_cancel_light;
        case KEY_ACTION_BAR_OPEN:
            return R.drawable.action_bar_open_light;
        case KEY_ACTION_BAR_UP:
            return R.drawable.action_bar_up_normal_light;
        case KEY_ACTION_BAR_UP_CHECKED:
            return R.drawable.action_bar_up_checked_light;
        case KEY_ACTION_BAR_DOWN:
            return R.drawable.action_bar_down_normal_light;
        case KEY_ACTION_BAR_DOWN_CHECKED:
            return R.drawable.action_bar_down_checked_light;
        case KEY_TOP_BAR_BG:
            return R.drawable.topbar_bg_light;
        case KEY_HOME_TAB_BACKGROUND:
            return R.drawable.home_tab_bg_light;
        case KEY_TOP_BAR_SEARCH:
            return R.drawable.topbar_btn_search_light;
        case KEY_TOP_BAR_LOGO:
            return R.drawable.logo_light;
        case KEY_TOP_BAR_SPLITTER:
            return R.drawable.topbar_navigation_light;
        case KEY_TOP_BAR_SHARE:
            return R.drawable.topbar_btn_share_light;
        case KEY_ACTION_BAR_FONT_S:
            return R.style.text_style_1b;
        case KEY_ACTION_BAR_BTN_BG:
            return R.drawable.action_bar_btn_bg;
        case KEY_TOP_BAR_FOLLOW:
            return R.drawable.master_follow_selector_light;
        case KEY_PROGRESSBAR:
            return R.drawable.progress_horizontal_light;
        case KEY_ACTION_BAR_CANCEL:
            return R.drawable.action_bar_cancel_light;
        case KEY_TOP_BAR_BTN_BG:
            return R.drawable.topbar_btn_bg_light;
        case KEY_HOME_TAB_INDICATOR:
            return R.drawable.main_tab_anim_light;
        case KEY_ACTION_BAR_START:
            return R.drawable.action_bar_start_light;
        case KEY_TOP_BAR_EXCHANGE:
        	return R.drawable.selector_btn_bg_light;
        }
        return 0;
    }

    /*
     * 返回深色主题资源
     */
    private static int getDarkResourceId(int resId) {

        switch (resId) {
        case KEY_HOME_TAB_INDEX:
            return R.drawable.main_tab_index_selector;
        case KEY_HOME_TAB_CATEGORY:
            return R.drawable.main_tab_category_selector;
        case KEY_HOME_TAB_RECOMMEND:
            return R.drawable.main_tab_recommend_selector;
        case KEY_HOME_TAB_RANK:
            return R.drawable.main_tab_rank_selector;
        case KEY_HOME_TAB_APP_MANAGER:
            return R.drawable.main_tab_app_manager_selector;
        case KEY_TAB_M:
            return R.drawable.tab_selector;
        case KEY_TAB_L:
            return R.drawable.tab_l_bg_selector;
        case KEY_TAB_R:
            return R.drawable.tab_r_bg_selector;
        case KEY_HOME_TAB_TEXT:
            return R.style.home_tab_text_style_dark;
        case KEY_TAB_TEXT:
            return R.style.tab_text_style_dark;
        case KEY_TOP_TITLE_TEXT:
            return R.style.text_style_3e;
        case KEY_TAB_BG:
            return R.drawable.tab_bg;
        case KEY_ACTION_BAR_BG:
            return R.drawable.action_bar_operation_bg;
        case KEY_ACTION_BAR_OPERATION_BG:
            return R.drawable.action_bar_operation_bg;
        case KEY_ACTION_BAR_FONT:
            return R.style.text_style_3e;
        case KEY_ACTION_BAR_FONT_M:
            return R.style.text_style_2e;
        case KEY_ACTION_BAR_SPLITTER:
            return R.drawable.action_bar_splitter;
        case KEY_HOME_TAB_BREATH:
            return R.drawable.master_breath_drawable;
        case KEY_ACTION_BAR_DOWNLOAD:
            return R.drawable.action_bar_download;
        case KEY_ACTION_BAR_PENDING:
            return R.drawable.action_bar_pending;
        case KEY_ACTION_BAR_INSTALL:
            return R.drawable.action_bar_install;
        case KEY_ACTION_BAR_UNINSTALL:
            return R.drawable.action_bar_cancel;
        case KEY_ACTION_BAR_OPEN:
            return R.drawable.action_bar_open;
        case KEY_ACTION_BAR_UP:
            return R.drawable.action_bar_up_normal;
        case KEY_ACTION_BAR_UP_CHECKED:
            return R.drawable.action_bar_up_checked;
        case KEY_ACTION_BAR_DOWN:
            return R.drawable.action_bar_down_normal;
        case KEY_ACTION_BAR_DOWN_CHECKED:
            return R.drawable.action_bar_down_checked;
        case KEY_TOP_BAR_BG:
            return R.drawable.topbar_bg;
        case KEY_HOME_TAB_BACKGROUND:
            return R.drawable.home_tab_bg;
        case KEY_TOP_BAR_SEARCH:
            return R.drawable.topbar_btn_search;
        case KEY_TOP_BAR_LOGO:
            return R.drawable.logo;
        case KEY_TOP_BAR_SPLITTER:
            return R.drawable.topbar_navigation;
        case KEY_TOP_BAR_SHARE:
            return R.drawable.topbar_btn_share;
        case KEY_ACTION_BAR_FONT_S:
            return R.style.text_style_1e;
        case KEY_ACTION_BAR_BTN_BG:
            return R.drawable.action_bar_btn_bg;
        case KEY_TOP_BAR_FOLLOW:
            return R.drawable.master_follow_selector;
        case KEY_PROGRESSBAR:
            return R.drawable.progress_horizontal;
        case KEY_ACTION_BAR_CANCEL:
            return R.drawable.action_bar_cancel;
        case KEY_TOP_BAR_BTN_BG:
            return R.drawable.topbar_btn_bg;
        case KEY_HOME_TAB_INDICATOR:
            return R.drawable.main_tab_anim;
        case KEY_ACTION_BAR_START:
            return R.drawable.action_bar_start;
        case KEY_TOP_BAR_EXCHANGE:
        	return R.drawable.selector_btn_bg_dark;
        }
        return 1;
    }
}
